﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

namespace Assets.My_Assets.Scripts.Aniamtion
{
    /// <summary>
    /// 序列帧动画
    /// </summary>
    public class FrameAnimation:MonoBehaviour
    {
        public Sprite[] Sprites;//帧动画
        public Image Image;

        private int index = 0;
        void Start()
        {
            Image = transform.Find("Image").GetComponent<Image>();
            Sprites = Resources.LoadAll<Sprite>("Animation/10_dark");
            StartCoroutine(PlayAnimation());
        }

        private IEnumerator PlayAnimation()
        {
            while (true)
            {
                yield return new WaitForSeconds(0.015f);
                index++;
                if (index >= Sprites.Length)
                {
                    index = 0;
                }
                Image.sprite = Sprites[index];
            }            
        }       
    }
}